import { fn_Guid } from '@/utils/uuidUtils'
import { ShipType, ShootMode, type Warship, Row, type WarShipModel } from './types'
import _ from 'lodash'

console.log('shipConfig执行一次')

/**
 * 生成一个num条舰船的数组（深拷贝生成）
 * @param shipConfig 舰船数据对象
 * @param num 条数
 * @returns 生成的舰船数组
 */
export const genShipList = (shipConfig: Warship, num: number) => {
  const shipList: Warship[] = []
  for (let i = 0; i < num; i++) {
    shipList.push(_.cloneDeep(shipConfig))
  }
  return shipList
}

// 通用的反小武器序列模板
const antiSmallSequence: [ShipType, ShipType, ShipType, ShipType, ShipType, ShipType] = [
  ShipType.Destroyer,
  ShipType.Frigate,
  ShipType.AircraftCarrier,
  ShipType.Battleship,
  ShipType.Battlecruisers,
  ShipType.Cruiser
]
// 通用的反大武器序列模板
const antiBigSequence: [ShipType, ShipType, ShipType, ShipType, ShipType, ShipType] = [
  ShipType.AircraftCarrier,
  ShipType.Battleship,
  ShipType.Battlecruisers,
  ShipType.Cruiser,
  ShipType.Destroyer,
  ShipType.Frigate
]

export const TaurusPulseCannon: Warship = {
  name: '斗牛原型',
  commandPoints: 8,
  shipTemplate: {
    standRow: Row.Front,
    shipType: ShipType.Destroyer
  },
  weaponList: [
    {
      name: '斗牛的主炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence,
      dpm: 11454
    }
  ]
}

export const Eris1HeavyCannon: Warship = {
  name: '阋神星重炮',
  commandPoints: 7,
  shipTemplate: {
    standRow: Row.Front,
    shipType: ShipType.Destroyer
  },
  weaponList: [
    {
      name: '阋神星的重炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence,
      dpm: 11454
    }
  ]
}

export const WingedHussarAntiShip: Warship = {
  name: '枪骑兵对舰型',
  commandPoints: 6,
  shipTemplate: {
    standRow: Row.Middle,
    shipType: ShipType.Destroyer
  },
  weaponList: [
    {
      name: '枪骑兵的重炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence,
      dpm: 1968
    },
    {
      name: '枪骑兵的风暴导弹',
      shootMode: ShootMode.Guided,
      attackSequence: antiSmallSequence,
      dpm: 2740
    }
  ]
}

export const MareSerenitatis: Warship = {
  name: '澄海对舰型',
  commandPoints: 5,
  shipTemplate: {
    standRow: Row.Back,
    shipType: ShipType.Frigate
  },
  weaponList: [
    {
      name: '澄海的超新星-白',
      shootMode: ShootMode.Guided,
      attackSequence: antiBigSequence,
      dpm: 5178
    }
  ]
}

export const Cas066Integrated: Warship = {
  name: 'CAS066综合型',
  commandPoints: 18,
  shipTemplate: {
    standRow: Row.Front,
    shipType: ShipType.Cruiser
  },
  weaponList: [
    {
      name: '066的雷火对舰火炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence,
      dpm: 6150
    },
    {
      name: '066的8联装鱼雷',
      shootMode: ShootMode.Guided,
      attackSequence: antiBigSequence,
      dpm: 4576
    }
  ]
}

export const CarilionRecon: Warship = {
  name: '卡利莱恩侦察',
  commandPoints: 4,
  shipTemplate: {
    standRow: Row.Front,
    shipType: ShipType.Frigate
  },
  weaponList: [
    {
      name: '卡利侦察的刮痧火炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence,
      dpm: 1125
    }
  ]
}

// ============新的格式=====================
export const TaurusPulseCannonModel: WarShipModel = {
  id: fn_Guid(),
  name: '斗牛原型',
  shipTemplate: {
    standRow: Row.Front,
    shipType: ShipType.Destroyer
  },
  weaponList: [
    {
      id: fn_Guid(),
      name: '斗牛的主炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence
    }
  ]
}

export const Eris1HeavyCannonModel: WarShipModel = {
  id: fn_Guid(),
  name: '阋神星重炮',
  shipTemplate: {
    standRow: Row.Front,
    shipType: ShipType.Destroyer
  },
  weaponList: [
    {
      id: fn_Guid(),
      name: '阋神星的重炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence
    }
  ]
}

export const WingedHussarAntiShipModel: WarShipModel = {
  id: fn_Guid(),
  name: '枪骑兵对舰型',
  shipTemplate: {
    standRow: Row.Middle,
    shipType: ShipType.Destroyer
  },
  weaponList: [
    {
      id: fn_Guid(),
      name: '枪骑兵的重炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence
    },
    {
      id: fn_Guid(),
      name: '枪骑兵的风暴导弹',
      shootMode: ShootMode.Guided,
      attackSequence: antiSmallSequence
    }
  ]
}

export const MareSerenitatisModel: WarShipModel = {
  id: fn_Guid(),
  name: '澄海对舰型',
  shipTemplate: {
    standRow: Row.Back,
    shipType: ShipType.Frigate
  },
  weaponList: [
    {
      id: fn_Guid(),
      name: '澄海的超新星-白',
      shootMode: ShootMode.Guided,
      attackSequence: antiBigSequence
    }
  ]
}

export const Cas066IntegratedModel: WarShipModel = {
  id: fn_Guid(),
  name: 'CAS066综合型',
  shipTemplate: {
    standRow: Row.Front,
    shipType: ShipType.Cruiser
  },
  weaponList: [
    {
      id: fn_Guid(),
      name: '066的雷火对舰火炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence
    },
    {
      id: fn_Guid(),
      name: '066的8联装鱼雷',
      shootMode: ShootMode.Guided,
      attackSequence: antiBigSequence
    }
  ]
}

export const CarilionReconModel: WarShipModel = {
  id: fn_Guid(),
  name: '卡利莱恩侦察',
  shipTemplate: {
    standRow: Row.Front,
    shipType: ShipType.Frigate
  },
  weaponList: [
    {
      id: fn_Guid(),
      name: '卡利侦察的刮痧火炮',
      shootMode: ShootMode.DirectFire,
      attackSequence: antiSmallSequence
    }
  ]
}

export const shipModelList = [
  TaurusPulseCannonModel,
  Eris1HeavyCannonModel,
  WingedHussarAntiShipModel,
  MareSerenitatisModel,
  Cas066IntegratedModel,
  CarilionReconModel
]

/**
 * 从舰船id查找到舰船名字
 * @param shipModelId
 */
export const convertShipModelIdToShipModelName = (shipModelId: string) => {
  return shipModelList.find((shipModel) => {
    return shipModelId == shipModel.id
  })?.name
}
/**
 * 从武器id查找到武器名字
 * @param weaponModelId
 */
export const convertWeaponModelIdToWeaponName = (weaponModelId: string) => {
  for (let i = 0; i < shipModelList.length; i++) {
    for (let j = 0; j < shipModelList[i].weaponList.length; j++) {
      if (shipModelList[i].weaponList[j].id == weaponModelId) {
        return shipModelList[i].weaponList[j].name
      }
    }
  }
  return undefined
}
/**
 * 根据id查找舰船型号
 * @param shipId 舰船的型号uuid
 */
export const findShipModelById = (shipId: string): WarShipModel | undefined => {
  return shipModelList.find((shipModel) => shipModel.id == shipId)
}
